﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using DeepTime.Shared.Entities;
using System.Collections.ObjectModel;
using DeepTime.DL.DataSources;
using DeepTime.DL.DataModels;
using System.Collections.Generic;

namespace DeepTime.Web.Services
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class DeepTimeImageMetaData
    {
        [OperationContract]
        public DeepZoomImageMetaDataEntity GetDeepZoomImage(string rowKey, string partitionKey)
        {
            //
            // Get item
            //
            DeepZoomImageMetaDataDataSource deepZoomImageMetaDataDataSource = new DeepZoomImageMetaDataDataSource();
            DeepZoomImageMetaDataDataModel data = deepZoomImageMetaDataDataSource.Select().Where(d => d.PartitionKey == partitionKey && d.RowKey == rowKey).FirstOrDefault();

            if (data != null)
            {
                return data.GetEntity();
            }
            else
            {
                return new DeepZoomImageMetaDataEntity();
            }
        }

        [OperationContract]
        public ObservableCollection<DeepZoomImageMetaDataEntity> GetDeepZoomImages()
        {
            //
            // Get all uploaded images meta data
            //
            DeepZoomImageMetaDataDataSource deepZoomImageMetaDataDataSource = new DeepZoomImageMetaDataDataSource();
            IEnumerable<DeepZoomImageMetaDataEntity> items = from img in deepZoomImageMetaDataDataSource.Select()
                                                             select img.GetEntity();

            return new ObservableCollection<DeepZoomImageMetaDataEntity>(items);
        }
    }
}
